/*
 user.go
 Created by hupfei on 2019-06-10
*/

package v1

import (
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/pkg/errors"
	"strconv"
	"time"
	"zimuzu_cvn_web_api/config"
	"zimuzu_cvn_web_api/model"
	"zimuzu_cvn_web_api/pkg/drive/redis"
	"zimuzu_cvn_web_api/pkg/e"
	"zimuzu_cvn_web_api/pkg/errno"
	"zimuzu_cvn_web_api/router/api"
	"zimuzu_cvn_web_api/router/api/web/middleware"
	"zimuzu_cvn_web_api/service"
	"zimuzu_cvn_web_api/service/cache"
	"zimuzu_cvn_web_api/service/flows"
)

type UserAPI struct {
}

func (a UserAPI) Name() string {
	return "user API"
}

func (a UserAPI) Bind() {
	userAPI := config.C.Router.Group("/v1/user", middleware.TrackLog(), middleware.AuthMiddleware())
	{
		userAPI.GET("cvntIssueRecord", recordList)
		userAPI.GET("cvntLog", cvntLog)
		userAPI.GET("accountInfo", accountInfo)
		userAPI.GET("pledge/available", cvnPledgeAvailable)
		userAPI.GET("miningInfo", miningInfo)
		userAPI.GET("pay/checkCode", checkCode)
		userAPI.GET("pay/checkPassword", checkPassword)
		userAPI.GET("pay/setPassword", setPayPassword)
		userAPI.GET("checkPayPassword", checkPayPassword)
		userAPI.GET("unavailableInfo", unavailableInfo)
		userAPI.GET("incomeList", incomeList)
		userAPI.GET("isSuperNode", isSuperNode)
	}
	cvntCountInfoAPI := config.C.Router.Group("/v1", middleware.TrackLog())
	{
		cvntCountInfoAPI.GET("cvntCountInfo", cvntCountInfo)
		cvntCountInfoAPI.GET("fixedDrawTask", fixedDrawTaskList)
		cvntCountInfoAPI.POST("node/login/v2", nodeLoginV2)
		cvntCountInfoAPI.GET("global/source/check", globalSourceCheck)
		cvntCountInfoAPI.GET("node/check/token", nodeCheckToken)
		cvntCountInfoAPI.POST("node/status/report", nodeStatusReport)
	}
}

func globalSourceCheck(c *gin.Context) {

	errno.OK.Info = "验证成功"
	var data []model.GlobalSourceCheckRes
	var temp model.GlobalSourceCheckRes
	var SourceList []string
	SourceList = []string{"taiwu", "wangxin"}
	for _, k := range SourceList {
		temp.Name = k
		if k == "taiwu" {
			temp.Status = 1
		} else {
			if time.Now().Unix() < 1590464295 {
				temp.Status = 1
			} else {
				temp.Status = 0
			}
		}
		data = append(data, temp)
	}

	api.SendResponse(c, errno.OK, data)
	return
}

// 3.6.4 修改支付密码
// Auth: hzp
func checkPassword(c *gin.Context) {

	uid, err := service.GetUserIdByRequest(c)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	var params model.PasswordModel
	err = c.ShouldBindWith(&params, binding.Query)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	Info, err := service.GetUserInfo(uid)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	if !e.CheckMd5Password(params.Password, Info.Password, Info.Salt) {
		api.SendResponse(c, errno.ErrPasswordIncorrect, nil)
	}

	var data model.Uuid
	data.U, err = service.SetRedisU(uid, 10*e.TimeFormatMin)
	if data.U == "" {
		api.SendResponse(c, errno.SystemErr, nil)
		return
	}

	errno.OK.Info = "验证成功"
	api.SendResponse(c, errno.OK, data)
	return
}

// 3.6.4 第四步
// Auth: hzp
type checkCodeParams struct {
	Code int    `form:"code" json:"code" binding:"required"`
	U    string `form:"u" json:"u" binding:"required"`
}

func checkCode(c *gin.Context) {

	uid, err := service.GetUserIdByRequest(c)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	var params checkCodeParams
	err = c.ShouldBindWith(&params, binding.Query)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	// 去校验 u 是否正确
	ok := service.IsPayPasswordChecked(uid, params.U)
	if !ok {
		api.SendResponse(c, errno.PhoneCodeCheckExpire, nil)
		return
	}

	Info, err := service.GetUserInfo(uid)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	// 校验验证码
	scene := service.SendCodeScenePay
	if errValid := service.ValidateCode(Info.PhoneNumber, scene, params.Code); errValid != nil {
		api.SendResponse(c, errValid, nil)
		return
	}

	var data model.Uuid
	data.U, err = service.SetRedisU(uid, 10*e.TimeFormatMin)
	if data.U == "" {
		api.SendResponse(c, errno.SystemErr, nil)
		return
	}

	errno.OK.Info = "验证成功"
	api.SendResponse(c, errno.OK, data)
	return
}

// 3.6.4 第五步
// Auth: hzp
type setPayPasswordParams struct {
	Password string `form:"password" json:"password" binding:"required"`
	U        string `form:"u" json:"u" binding:"required"`
}

func setPayPassword(c *gin.Context) {

	uid, err := service.GetUserIdByRequest(c)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	var params setPayPasswordParams
	err = c.ShouldBindWith(&params, binding.Query)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	// 去校验 u 是否正确
	// 新注册的初始化支付密码不需要校验上一步
	if !service.CheckRegMark(uid) {
		CheckCacheKey := cache.GetPayPasswordCheckKey(uid, params.U)
		u, err := redis.Get(CheckCacheKey)
		if err != nil || u != "1" {
			api.SendResponse(c, errno.ErrUserNotFound, nil)
			return
		}
	}

	if params.Password == e.EmptyStrMd5 {
		api.SendResponse(c, errno.EmptyMd5PayPassword, nil)
		return
	}

	err = service.SetPayPassword(uid, params.Password)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	errno.OK.Info = "修改成功"
	api.SendResponse(c, errno.OK, nil)
	return
}

//cvnt发放记录
func recordList(c *gin.Context) {
	var params = model.NewDefaultPageParams()
	err := c.ShouldBindQuery(&params)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	uid, _ := service.GetUserIdByRequest(c)
	res, err := service.GetIssueRecordList(uid, params.Per, params.Page)
	if err != nil {
		api.SendResponse(c, errors.New("查询cvnt发放记录失败"), nil)
		return
	}
	errno.OK.Info = "返回cvnt发放记录成功"
	api.SendResponse(c, errno.OK, res)
	return
}

//cvnt 账户明细
func cvntLog(c *gin.Context) {
	var params = model.NewDefaultPageParams()
	err := c.ShouldBindQuery(&params)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	uid, _ := service.GetUserIdByRequest(c)
	res, err := service.GetCVNLogList(uid, params.Per, params.Page)
	if err != nil {
		api.SendResponse(c, errors.New("查询cvnt账户明细失败"), nil)
		return
	}
	errno.OK.Info = "返回cvnt账户明细成功"
	api.SendResponse(c, errno.OK, res)
	return
}

//全网挖矿机CVNT持有信息
func cvntCountInfo(c *gin.Context) {
	res, err := service.GetWholeNetworkInfo()
	if err != nil {
		api.SendResponse(c, errors.New("查询全网cvnt持有信息失败"), nil)
		return
	}
	errno.OK.Info = "返回全网挖矿机cvnt持有信息成功"
	api.SendResponse(c, errno.OK, res)
	return
}

type accountInfoResponsedata struct {
	Nickname       string `json:"nickname"`
	Uid            int64  `json:"uid"`
	AccountBalance struct {
		TotalCvnt  float64 `json:"totalCvnt"`
		EnableCvnt float64 `json:"enableCvnt"`
		UnableCvnt float64 `json:"unableCvnt"`
		Point      int     `json:"point"`
	} `json:"accountBalance"`
	CloudWallet struct {
		TotalCvnt float64 `json:"totalCvnt"`
	} `json:"cloudWallet"`
}

//账户信息
//Auth: Xu
func accountInfo(c *gin.Context) {
	var responseData accountInfoResponsedata
	uid, _ := service.GetUserIdByRequest(c)
	userInfo, err := service.GetUserInfo(uid)
	if err != nil {
		api.SendResponse(c, errors.New("查询账号CVNT信息失败"), nil)
		return
	}
	responseData.Nickname = userInfo.Nickname
	responseData.Uid = userInfo.Uid

	//账户CVNT信息
	cvntAmount, err := service.GetUserCvnAmountByUid(uid)
	if err != nil {
		api.SendResponse(c, errors.New("查询账号CVNT信息失败"), nil)
		return
	}
	responseData.AccountBalance.UnableCvnt = cvntAmount.FrozenBalance
	responseData.AccountBalance.EnableCvnt = cvntAmount.Balance
	responseData.AccountBalance.TotalCvnt = cvntAmount.FrozenBalance + cvntAmount.Balance
	responseData.AccountBalance.Point = userInfo.Point

	//云钱包cvnt数量信息
	//cloudCvnt, err := service.GetCloudWalletCvnt(uid)
	//if err != nil{
	//	api.SendResponse(c, errors.New("查询云钱包CVNT信息失败"), nil)
	//	return
	//}
	//responsedata.CloudWallet.TotalCvnt = cloudCvnt

	errno.OK.Info = "返回账户信息成功"
	api.SendResponse(c, errno.OK, responseData)
	return
}

type miningInfoResponseData struct {
	Linux  *linuxMiningInfo `json:"linux,omitempty"`
	Pc     pcMiningInfo     `json:"pc,omitempty"`
	Router struct {
		MyTotalUpload           string  `json:"myTotalUpload"`
		MyTotalCvntAmount       float64 `json:"myTotalCvntAmount"`
		MyRouterCount           int64   `json:"myRouterCount"`
		MyMiningRouterCount     int64   `json:"myMiningRouterCount"`
		MyTodayUpload           string  `json:"myTodayUpload"`
		MyTodayCvntAmount       float64 `json:"myTodayCvntAmount"`
		MyTodayUploadUpdateTime string  `json:"myUploadUpdateTime"`
		TokenNum                int     `json:"tokenNum"`
	} `json:"router,omitempty"`
}
type linuxMiningInfo struct {
	TotalNodeCount     int     `json:"totalNodeCount"`
	MyTotalUpload      string  `json:"myTotalUpload"`
	MyTotalCvntAmount  float64 `json:"myTotalCvntAmount"`
	MyTotalNodeCount   int64   `json:"myTotalNodeCount"`
	MyTodayUpload      string  `json:"myTodayUpload"`
	MyTodayCvntAmount  float64 `json:"myTodayCvntAmount"`
	MyUploadUpdateTime string  `json:"myUploadUpdateTime"`
	MyMiningCount      int64   `json:"myMiningCount"`
	TokenNum           int     `json:"tokenNum"`
}

type pcMiningInfo struct {
	MyTotalUpload           string  `json:"myTotalUpload"`
	MyTotalCvntAmount       float64 `json:"myTotalCvntAmount"`
	MyRouterCount           int64   `json:"myRouterCount"`
	MyMiningRouterCount     int64   `json:"myMiningRouterCount"`
	MyTodayUpload           string  `json:"myTodayUpload"`
	MyTodayCvntAmount       float64 `json:"myTodayCvntAmount"`
	MyTodayUploadUpdateTime string  `json:"myUploadUpdateTime"`
	TokenNum                int     `json:"tokenNum"`
}

//获取用户挖矿信息
//Auth: Xu
func miningInfo(c *gin.Context) {
	response := miningInfoResponseData{}
	uid, _ := service.GetUserIdByRequest(c)
	routerMingInfo, err := service.GetRouterMiningInfo(uid, model.NodeTypeRouter)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	nodeNum, err := model.GetUserPledgedNodeNum(uid)
	if err != nil {
		api.SendResponse(c, errno.DbSearchError, nil)
		return
	}

	//路由器流量、cvnt、数量、质押cvnt
	response.Router.MyTotalUpload = e.SizeFormat(routerMingInfo.ExchangeSize*1024, 2)
	response.Router.MyTotalCvntAmount = routerMingInfo.Cvn
	response.Router.MyRouterCount = routerMingInfo.Counts
	response.Router.MyMiningRouterCount = routerMingInfo.MiningCounts
	response.Router.TokenNum = nodeNum.RouterNum

	//路由器今日上传量
	totalUpload, _ := model.GetUserTodayUpload(uid, model.NodeTypeRouter)
	response.Router.MyTodayUpload = e.SizeFormat(totalUpload*1024, 2)

	//路由器今日预计获得cvnt
	nodeData, err := service.GetUserAllNodeList(uid, model.NodeTypeRouter)
	if err != nil {
		api.SendResponse(c, errors.New("远程查询预计收益失败"), nil)
		return
	}
	response.Router.MyTodayCvntAmount = nodeData.TodayCvnt

	//路由器挖矿更新时间
	response.Router.MyTodayUploadUpdateTime, err = model.GetMiningInfoUpdateTime(uid, model.NodeTypeRouter)

	//linux相关数据
	netMillInfo := service.GetNetMillInfo()
	linuxMiningInfo := linuxMiningInfo{}
	userLinuxFlow, _ := service.GetLinuxFlowSum(uid)
	myTotalNodeCount, _ := service.GetNodeCount(uid, 1, model.NodeTypeLinux)
	e.Log("info", "[NodeCount]", uid, "=", uid, "&NodeCount=", myTotalNodeCount)
	if userLinuxFlow.FlowSum != 0 || myTotalNodeCount != 0 {
		linuxMiningInfo.MyTotalUpload = e.SizeFormat(userLinuxFlow.FlowSum, 2)
		linuxMiningInfo.MyTotalNodeCount = myTotalNodeCount
		linuxMiningInfo.MyUploadUpdateTime = userLinuxFlow.UpdateTime
		linuxMiningInfo.MyTotalCvntAmount, _ = service.GetLinuxCvnt(uid)
		linuxMiningInfo.TotalNodeCount = netMillInfo.TotalNodeCount
		todayUpload, _ := service.GetLinuxTodayUpload(uid)
		linuxMiningInfo.MyTodayUpload = e.SizeFormat(todayUpload, 2)
		//账户CVNT信息
		linuxMiningInfo.TokenNum = nodeNum.LinuxNum

		//用户节点数
		linuxMiningInfo.MyMiningCount, err = service.GetNodeCount(uid, 2, model.NodeTypeLinux)
		if err != nil {
			api.SendResponse(c, err, nil)
			return
		}
		response.Linux = &linuxMiningInfo
	} else {
		response.Linux = nil
	}

	//pc流量、cvnt、数量、质押cvnt
	pcMingInfo, err := service.GetRouterMiningInfo(uid, model.NodeTypePc)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	response.Pc.MyTotalUpload = e.SizeFormat(pcMingInfo.ExchangeSize*1024, 2)
	response.Pc.MyTotalCvntAmount = pcMingInfo.Cvn
	response.Pc.MyRouterCount = pcMingInfo.Counts
	response.Pc.MyMiningRouterCount = pcMingInfo.MiningCounts

	//今日上传量
	pcTotalUpload, _ := model.GetUserTodayUpload(uid, model.NodeTypePc)
	response.Pc.MyTodayUpload = e.SizeFormat(pcTotalUpload*1024, 2)

	//今日预计获得cvnt
	nodeData, err = service.GetUserAllNodeList(uid, model.NodeTypePc)
	if err != nil {
		api.SendResponse(c, errno.DbSearchError, nil)
		return
	}
	response.Pc.MyTodayCvntAmount = nodeData.TodayCvnt

	//路由器挖矿更新时间
	response.Pc.MyTodayUploadUpdateTime, _ = model.GetMiningInfoUpdateTime(uid, model.NodeTypePc)
	response.Pc.TokenNum = nodeNum.PcNum

	errno.OK.Info = "返回挖矿信息成功"
	api.SendResponse(c, errno.OK, response)
	return
}

//质押提取的可用余额
//Auth: hzp
func cvnPledgeAvailable(c *gin.Context) {

	var params model.StatusModel
	err := c.ShouldBindQuery(&params)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	Uid, _ := c.Get("userId")
	var UserId int64
	if Uid == nil {
		UserId, _ = strconv.ParseInt(c.Query("userId"), 10, 64)
	} else {
		UserId = Uid.(int64)
	}
	available, err := service.GetPledgeAvailable(UserId, model.PledgeLinux)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}
	errno.OK.Info = "数据查询正常"
	api.SendResponse(c, errno.OK, available)
	return
}

//检查是否已设置支付密码
//Auth: Xu
func checkPayPassword(c *gin.Context) {
	uid, _ := service.GetUserIdByRequest(c)

	hasPayPassword := 1
	if res, err := service.CheckPayPasswordExist(uid); err == nil && res {
		hasPayPassword = 2
	}
	responseData := map[string]interface{}{
		"hasPayPassword": hasPayPassword,
	}

	errno.OK.Info = "查询成功"
	api.SendResponse(c, errno.OK, responseData)
	return
}

type keyCacheList struct {
	Key  string `json:"key"`
	Time int64  `json:"key"`
}

func fixedDrawTaskList(c *gin.Context) {

	if c.Query("key") != config.C.FlowKey || c.Query("key") == "" {
		api.SendResponse(c, errno.IllegalErr, nil)
		return
	}

	var cacheKey []keyCacheList = make([]keyCacheList, 3)
	cacheKey[1].Key = e.UserRedisPrefix + e.RedisDrawListKey
	cacheKey[1].Time = time.Now().Unix() + 24*3600
	cacheKey[2].Key = e.UserRedisPrefix + e.RedisRouterDrawListKey
	cacheKey[2].Time = time.Now().Unix()

	TaskList, err := model.FixedUnDoTask()
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	iss := 0
	for _, k := range TaskList {
		InsIdStr := strconv.FormatInt(k.TaskId, 10)
		score, err := redis.ZScore(cacheKey[k.Type].Key, InsIdStr)
		if err == nil && score > 0 {
			continue
		}
		_, err2 := redis.ZAdd(cacheKey[k.Type].Key, InsIdStr, cacheKey[k.Type].Time)
		if err2 != nil {
			err = model.RemoveDrawTask(config.C.DB.DB, k.TaskId)
			if err != nil {
				api.SendResponse(c, err, nil)
				return
			}
		}
		iss++
	}

	errno.OK.Info = "修复数据完成，总计多少条：" + strconv.Itoa(iss)
	api.SendResponse(c, errno.OK, nil)
	return
}

/*
 * @ Author: hupfei
 * @ Description: 不可用额度明细
 **/
func unavailableInfo(c *gin.Context) {
	var params = model.NewDefaultPageParams()
	err := c.ShouldBindQuery(&params)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}
	uid, _ := service.GetUserIdByRequest(c)

	data, err := service.UnavailableInfoList(uid, params.Page, params.Per)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}
	errno.OK.Info = "返回不可用额度明成功"
	api.SendResponse(c, errno.OK, data)
	return
}

/*
 * @ Author: hupfei
 * @ Description: 3.8.3 旷工贡献列表
 **/
func incomeList(c *gin.Context) {
	uid, _ := service.GetUserIdByRequest(c)
	re, err := service.IncomeList(uid, 1, 500)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}
	errno.OK.Info = "获取旷工贡献列表成功"
	api.SendResponse(c, errno.OK, re)
	return
}

//判断该用户是否是超级节点
func isSuperNode(c *gin.Context) {
	uid, _ := service.GetUserIdByRequest(c)
	ok, err := model.CheckUserIsSuperNode(uid)
	if err != nil {
		api.SendResponse(c, err, nil)
	}
	var isSuperNode = 0
	if ok {
		isSuperNode = 1
	}
	var re = map[string]interface{}{
		"isSuperNode": isSuperNode,
	}
	errno.OK.Info = "查询成功"
	api.SendResponse(c, errno.OK, re)
	return
}

// 3.2.2 终端登录
func nodeLoginV2(c *gin.Context) {

	// 1、参数校验
	var params model.NodeLoginV2Params
	err := c.BindJSON(&params)
	if err != nil {
		e.Log("info", "params, ERROR ", params)
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}
	e.Log("info", "params", params)

	// 密码校验流程
	var user model.UserLoginResponse

	// 2、校验是否存在账号  优先级 校验 邮箱 > 用户名 > 手机号
	isFound := false
	if e.IsEmail(params.UserName) {
		user, _ = model.GetUserFromLogin(3, params.UserName)
		if user.Uid > 0 {
			isFound = true
		}
		e.Log("info", "ErrUserNotFound [33], ", user.Uid)
	}

	if !isFound && e.IsPhone(params.UserName) {
		user, _ = model.GetUserFromLogin(2, params.UserName)
		if user.Uid > 0 {
			isFound = true
		}
		e.Log("info", "ErrUserNotFound [23], ", user.Uid)
	}

	if !isFound {
		user, _ = model.GetUserFromLogin(1, params.UserName)
		if user.Uid > 0 {
			isFound = true
		}
	}

	if !isFound {
		e.Log("info", "ErrUserNotFound [3]")
		api.SendResponse(c, errno.ErrUserNotFound, nil)
		return
	}

	way := 0
	if params.Version != "" {
		way = 1
	}

	// 网心接口上线才可以加这个
	if params.Version != "1.1.0" {
		// api.SendResponse(c, errno.VersionLow, nil)
		// return
	}

	// 判断用户输入的用户名是否已经注册过
	var dataReturn model.LoginRequest
	if params.Password == "" {
		dataReturn.Uid = user.Uid
		nodeId, nodeName, err := flows.CheckNode(user.Uid, params.Mac)
		if err != nil {
			api.SendResponse(c, err, nil)
			return
		}
		dataReturn.NodeId = nodeId
		dataReturn.Name = nodeName
		errno.OK.Info = "获取成功"
		api.SendResponse(c, errno.OK, dataReturn)
		return
	}

	if !e.CheckPasswordByWay(params.Password, user.Password, user.Salt, way) {
		e.Log("info", "CheckPassword [3] ,", params.Password, user.Password, user.Salt)
		api.SendResponse(c, errno.ErrUserNotFound, nil)
		return
	}

	// 3、校验结点是否已经注册梨享结点
	nodeId, nodeName, err := flows.CheckNode(user.Uid, params.Mac)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	// 更新节点信息
	var localIp string
	for _, k := range params.Ips {
		if k.IsUsed == true {
			localIp = k.Ip
		}
	}
	err = model.UpdateMgNodeLocalIp(nodeId, localIp, c.ClientIP())
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	// 4、校验是否 账号密码正确  正确：写入token表、写入redis
	err, token := flows.AddUserToken(user.Uid, 5, "") // 暂时不考虑极光推送ID
	if err != nil {
		api.SendResponse(c, errno.ErrTokenError, nil)
		return
	}

	dataReturn.Uid = user.Uid
	dataReturn.Token = token
	dataReturn.NodeId = nodeId
	dataReturn.Name = nodeName
	errno.OK.Info = "用户登录成功"
	api.SendResponse(c, errno.OK, dataReturn)
	return
}

// 3.2.3 校验token
func nodeCheckToken(c *gin.Context) {

	// 1、参数校验
	var params model.UidTokenParams
	err := c.ShouldBindWith(&params, binding.Query)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	err, bo := flows.CheckUserToken(params.Uid, params.Token)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	if !bo {
		api.SendResponse(c, errno.TokenError, nil)
		return
	}

	errno.OK.Info = "校验成功"
	api.SendResponse(c, errno.OK, nil)
	return
}

// 节点服务状态上报
// type: 1-网心 2-钛雾
// Auth: hzp
func nodeStatusReport(c *gin.Context) {

	// 参数校验
	var params model.NodeStatusReportParams
	err := c.BindJSON(&params)
	if err != nil {
		api.SendResponse(c, errno.ParamsError, nil)
		return
	}

	// 将数据上报上去
	err = flows.ReportStatus(params)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	errno.OK.Info = "上报成功"
	api.SendResponse(c, errno.OK, nil)
	return
}
